package com.wangcang.widgetlibrary.share;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.dialog.ProgressOwnDialogUtils;
import com.wangcang.widgetlibrary.tools.PermissionUtils;
import com.wangcang.widgetlibrary.tools.ToastUtils;

import java.util.List;

public class ShareActivity extends AppCompatActivity implements PermissionUtils.PermissionCallbacks{

    private Button mShareActivityBtn;
    private int permissionCode = 10001;
    private String [] permissionList = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);

        mShareActivityBtn = (Button) findViewById(R.id.share_activity_btn);

        final ShareContent content = new ShareContent();
        content.setContent("我是内容凤飞飞凤飞飞凤飞飞凤飞飞凤飞飞凤飞飞凤飞飞凤飞飞");
        content.setTitle("我是标题");
        content.setImageUrl("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=350573396,473598857&fm=26&gp=0.jpg");
        content.setUrl("http://www.baidu.com");
        content.setPhoneNum("23234141");
        content.setMessage("我是短信内容");
        content.setCopyContent("我是拷贝的内容");
        content.setShareDestname("目的名字");

        mShareActivityBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                SharePopuwindow.getInstance(ShareActivity.this)
//                        .setContent(content)
//                        .showPop();
                ProgressOwnDialogUtils.show(ShareActivity.this,"加载啊....");
            }
        });

        permissionList = new String[]{Manifest.permission.CALL_PHONE};

        PermissionUtils.requestPermissions(this,permissionList,permissionCode);
    }



    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        if(requestCode == permissionCode && perms.size() == 1) {//同意了全部的权限

        }
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        //调用了一次拒绝权限认为失败
        if(requestCode == permissionCode){
            ToastUtils.showToast("拒绝了权限" + permissionList[0]);
            PermissionUtils.permissionDialog(this, perms, null);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }
}
